package com.mobilezu.mobile.pushserver.util;

import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationFactory;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;


public class ConfigManager {

	private static final Log log = LogFactory.getLog(ConfigManager.class);

	private static Configuration config;
	private static ConfigManager instance;

	private ConfigManager() {
		loadConfig();
	}

	/**
	 * ����һ������ģʽ��ConfigManger.
	 * 
	 * @return the instance
	 */
	public static ConfigManager getInstance() {
		if (instance == null) {
			synchronized (ConfigManager.class) {
				instance = new ConfigManager();
			}
		}
		return instance;
	}

	/**
	 * ����Ĭ�ϵ������ļ�
	 */
	public void loadConfig() {
		loadConfig("config.xml");
	}

	/**
	 * �����ض��������ļ�
	 * 
	 * @param configFileName
	 *            the file name
	 */
	public void loadConfig(String configFileName) {
		try {
			ConfigurationFactory factory = new ConfigurationFactory(
					configFileName);
			config = factory.getConfiguration();
			log.info("Configuration loaded: " + configFileName);
		} catch (Exception ex) {
			log.error(ex.getMessage(), ex);
			throw new RuntimeException("Configuration loading error: "
					+ configFileName, ex);
		}
	}

	/**
	 * ��ȡ�����˵������ļ�����
	 * 
	 * @return the configuration
	 */
	public Configuration getConfig() {
		return config;
	}

}
